﻿<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            品牌<small>列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">系统设置</a></li>
            <li class="active">品牌列表</li>
        </ol>
    </section>
    <section>
        <div class="col-xs-12">
            <div class="box box-primary ">
                <!-- form start -->
            </div>
        </div>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header my_search">
                        <select style="width:120px;" class="form-control" id="brand_status">
                            <option value="-1">-订单状态-</option>
                            <option value="1">启用</option>
                            <option value="0">禁用</option>
                        </select>
                        <input type="text" style="width:120px;" class="form-control pull-left" id="brand_name" placeholder="品牌名">
                        <button type="button" class="btn btn-default " id="btnSearch"><i class="fa fa-search"></i> 搜索</button>
                    </div>
                    <div class="box-body">
                        <table id="DataList" class="table table-bordered table-striped table-hover ">
                            <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>品牌名称</th>
                                    <th>图片</th>
                                    <th>排序</th>
                                    <th>所属商家</th>
                                    <th>状态</th>
                                    <th>是否置顶</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody> </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
@section JS{
    <script>
        $(function () {

            //初始化表格
            GenerateTable();
            //搜索事件
            $("#btnSearch").on("click", function () {
                u_table.fnDestroy();
                GenerateTable();
            });

        });

        //生成表格
        function GenerateTable() {
            u_table = $('#DataList').dataTable({
                "lengthChange": true,
                "searching": false,
                "ordering": false,
                "iDisplayLength": 10,
                "bProcessing": true,
                "bServerSide": true,
                "sScrollX": true,
                "bAutoWidth":false,
                "fnServerParams": function (aoData) {
                    var brand_name = $.trim($("#brand_name").val());
                    var brand_status = $("#brand_status").val();
                    aoData.push(
                        { "name": "brand_status", "value": brand_status },
                        { "name": "brand_name", "value": brand_name }
                    );
                },
                "sAjaxSource": "/SystemSetting/GetBrandsByPage",
                "aoColumns": [
                    { "mDataProp": 'brand_id' },
                    { "mDataProp": 'brand_name' },
                    {
                        "mDataProp": 'logo', "mRender": function (data, type, full) {
                            return data == null || data == '' ? "" : "<img style='max-height:35px;' src='" + domain + data + "' />"
                        }
                    },
                    { "mDataProp": 'sort' },
                    { "mDataProp": 'company_name' },
                    {
                        "mDataProp": 'status', "mRender": function (data, type, full) {
                            if (data == 1) {
                                return '<a style="text-decoration:none" class="btn btn-success" onClick="user_noPass(this,' + full.brand_id + ')" href="javascript:;" title="点击禁用">启用</a>';
                            } else {
                                return '<a style="text-decoration:none" class="btn btn-danger" onClick="user_pass(this,' + full.brand_id + ')" href="javascript:;" title="点击启用">禁用</a>';
                            }
                        }
                    },
                    {
                        "mDataProp": 'isTop', "mRender": function (data, type, full) {
                            if (data) {
                                return '<a style="text-decoration:none" class="btn btn-success" onClick="user_noPass(this,' + full.brand_id + ')" href="javascript:;" title="点击禁用">置顶</a>';
                            } else {
                                return '<a style="text-decoration:none" class="btn btn-danger" onClick="user_pass(this,' + full.brand_id + ')" href="javascript:;" title="点击启用">常规</a>';
                            }
                        }
                    },
                    {
                        "mDataProp": 'brand_id', "mRender": function (data, type, full) {
                            return ' <a href="javascript:void();" onclick ="admin_edit(\'编辑品牌\',\'/SystemSetting/AddBrand\',' + data + ',800,500)" class="btn btn-default"  title="编辑商品分类" >编辑</a> ';
                        }
                    }
                ]
            });
        }

        /*编辑*/
        function admin_edit(title, url, id, w, h) {
            layer_show(title, url,id, w, h);
        }
       /*禁用启用*/
        function brand_lock(obj, id, isLock) {
            var txt = isLock == 0? "启用" : "禁用";
            var reTxt = isLock == 0 ? "禁用" : "启用";
            layer.confirm('确认' + txt + '?', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetBrandIsUse/",
                    dataType: "json",
                    data: { id: id, isUse: (isLock == 1 ? 0 : 1) },
                    success: function (data) {
                        if (data.status == "y") {
                            layer.msg('操作成功!', { time: 1200 }, function () {
                                $(obj).text(reTxt).attr("onClick", "brand_lock(this," + id + "," + (isLock == 1 ? 0 : 1) + ")").attr("title", "点击" + reTxt);
                                $(obj).parent().parent().find("td:nth-last-child(3)").html(isLock == 0 ? "启用" : "<label style='color:red;'> 禁用</label>");
                            });
                        }
                        else {
                            layer.msg(data.info, { time: 1200 });
                        }
                    }
                });

            });
        }
        /*置顶*/
        function brand_top(obj, id, isTop) {
            var txt = isTop? "取消置顶": "置顶" ;
            var reTxt = isTop? "置顶":"取消置顶" ;
            layer.confirm('确认' + txt + '?', function (index) {
                $.ajax({
                    type: "post",
                    url: "/Goods/SetBrandTop/",
                    dataType: "json",
                    data: { id: id, isUse: (isTop ? 0 : 1) },
                    success: function (data) {
                        if (data.status == "y") {
                            layer.msg('操作成功!', { time: 1200 }, function () {
                                $(obj).text(reTxt).attr("onClick", "brand_top(this," + id + "," + (isTop? 0 : 1) + ")").attr("title", "点击" + reTxt);
                                $(obj).parent().parent().find("td:nth-last-child(2)").html(isTop?"常规": "<label style='color:red;'> 置顶</label>");
                            });
                        }
                        else {
                            layer.msg(data.info, { time: 1200 });
                        }
                    }
                });

            });
        }

    </script>


}